package com.example.apiusernacosseata.controller;

import com.example.apiusernacosseata.feign.OrderFeign;
import com.example.apiusernacosseata.mapper.UserMapper;
import com.wu.common.entity.ResultData;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author whx
 * @date 2022/3/8
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderFeign orderFeign;

    @GetMapping("hello")
    public String hello(){
        return "hello";
    }

    @PostMapping("/update")
    @GlobalTransactional(name = "update-user",rollbackFor = Exception.class)
    public ResultData update(int id){
        System.out.println("xid: "+ RootContext.getXID());
        userMapper.updateNameById(id);
        orderFeign.orderUpdate(id);
        return new ResultData().SUCCESS("success");
    }
}
